package com.open.fei.listener;

import cn.hutool.bloomfilter.BloomFilter;
import com.open.fei.config.BloomFilterConfig;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 重复消费（负载均衡模式）
 * @author zhaoYuFei
 */
@Component
@RocketMQMessageListener(topic = "powernodes",
        consumerGroup = "ReMsg",
        messageModel = MessageModel.CLUSTERING
)
//直接获得消息本体
public class ReMsgListener implements RocketMQListener<MessageExt> {
    @Autowired
    private BloomFilterConfig bloomFilterConfig;
    @Override
    public void onMessage(MessageExt s) {
        BloomFilter bloomFilter = bloomFilterConfig.messageBloomFilter();
        if (!bloomFilter.contains(s.getMsgId())){
            System.out.println("执行消费信息业务");
        }else {
            bloomFilter.add(s.getMsgId());
        }
    }
}
